<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
</head>
<body>

<p id="demo">单击按钮获取按钮元素中onclick属性的值</p>
<button onclick="myFunction()">点我</button>
<script>
    function myFunction(){
        let a=document.getElementsByTagName("BUTTON")[0];
        let x=document.getElementById("demo");
        x.innerHTML=a.attributes.getNamedItem("onclick").textContent;
    }
</script>
<p><strong>注意:</strong> Internet Explorer 8 及更早之前的版本不支持getNamedItem 方法。</p>

</body>
</html>